package com.walleipt.corgi.api.common;

import org.apache.commons.lang3.RandomUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.walle.ak47.commons.utils.json.GBuilder;
import com.walleipt.corgi.api.common.dao.Page;
import com.walleipt.corgi.api.common.dao.h2.H2SmartDao;
import com.walleipt.corgi.api.ex._HashMap;

public class H2ServerInitLoader {
	
	private final static Logger logger = LoggerFactory.getLogger(H2ServerInitLoader.class);
	
	public static void initLoadData() {
		
		 
		H2SmartDao.crateTable("create table userinfo( id int not null auto_increment , name varchar(50), PRIMARY KEY(id)  ) ;");
		
		for( int i=0; i<100; i++)
		{
			H2SmartDao.save( "userinfo", new _HashMap<String,Object>().add("name", "_"+RandomUtils.nextInt(1, 10000000))) ;
			if (i%100==0)
				logger.info( ""+i );
		}
		
		
		Page page1 = H2SmartDao.selectForPage(1, 3, "select * from userinfo" ) ;
		logger.info( GBuilder.toJson( page1 ) );
		Page page2 = H2SmartDao.selectForPage(2, 3, "select * from userinfo" ) ;
		logger.info( GBuilder.toJson( page2 ) );
	}
}
